using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using SumGam.Globals;
using SumGam.Structs;
using SumGam.Classes;

namespace SumGam
{
    public class DialogState : BaseState
    {
        public int Height;
        public List<string> Pages;
        public string HeaderText;
        public bool IncludeHeader;
        public int CurPage;
        public Delegates.Generic OnFinish;
        public Color BGColor;
        public Color BorderColor;
        public Color TextColor;
        public int BorderWidth;
        public SpriteFont TextFont;
        public SpriteFont HeaderFont;
        public Vector2 FontPos;
        public Vector2 HeaderPos;
        public DialogState(string HeaderText, int Height, int BorderWidth, bool IncludeHeader, Color BGColor, Color BorderColor, Color TextColor, SpriteFont TextFont, SpriteFont HeaderFont)
        {
            this.Height = Height;
            Pages = new List<string>();
            this.HeaderText = HeaderText;
            this.IncludeHeader = IncludeHeader;
            CurPage = 0;
            this.BGColor = BGColor;
            this.BorderColor = BorderColor;
            this.BorderWidth = BorderWidth;
            this.TextColor = TextColor;
            this.TextFont = TextFont;
            this.HeaderFont = HeaderFont;
            this.FontPos = new Vector2(10 + 5, 480 - Height + 5);
            this.HeaderPos = new Vector2((480 / 2) - (HeaderFont.MeasureString(HeaderText).X / 2), 480 - Height - 60 + BorderWidth + (HeaderFont.MeasureString(HeaderText).Y / 2) + 5);
        }
        public override void OnEnter(BaseState laststate)
        {
            CurPage = 0;
        }
        public void AddPage(string page)
        {
            Pages.Add(page);
        }
        public override void Update()
        {
            if (Helpers.GetKeyState(Keys.Enter).JustPressed)
            {
                if (CurPage == Pages.Count - 1)
                {
                    OnFinish();
                }
                else
                {
                    CurPage++;
                }
            }
        }
        public override void Draw()
        {
            Rendering.spriteBatch.Begin();
            Drawing.DrawBox(new Rectangle(10, 480 - Height, 480 - 20, Height), BorderWidth, BGColor, BorderColor);
            Rendering.spriteBatch.DrawString(TextFont, Pages[CurPage], FontPos, TextColor);
            if (IncludeHeader)
            {
                Drawing.DrawBox(new Rectangle(10, 480 - Height - 60 + BorderWidth, 480 - 20, 60), BorderWidth, BGColor, BorderColor);
                Rendering.spriteBatch.DrawString(HeaderFont, HeaderText, HeaderPos, TextColor);
            }
            Rendering.spriteBatch.End();
        }
    }
}